//
//  HomeViewController.swift
//  PutaoMaternityMatron
//
//  Created by xianzhiliao on 2017/3/20.
//  Copyright © 2017年 Putao. All rights reserved.
//

import UIKit

private let reuseIdentifierHeader = "headerCell"
private let reuseIdentifierContact = "contactCell"

protocol HomeViewControllerDelegate {
    func didClikDetail()
    func didClikOrder()
    func didClikContact()
}

class HomeViewController: UICollectionViewController ,UICollectionViewDelegateFlowLayout,HomeViewControllerDelegate {
    
    override func viewDidAppear(_ animated: Bool) {
        self.navigationController?.setNavigationBarHidden(true, animated: true)
    }
    override func viewWillDisappear(_ animated: Bool) {
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Uncomment the following line to preserve selection between presentations
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: UICollectionViewDataSource

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 2
    }


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of items
        return 1;
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
        let cell = UICollectionViewCell()
        if indexPath.section == 0 {
            let cell :HeaderCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierHeader, for: indexPath) as! HeaderCell
            cell.delegate = self
            return cell
        }
        else if indexPath.section == 1 {
            let cell :ContactCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifierContact, for: indexPath) as! ContactCell
            cell.delegate = self
            return cell
        }
        // Configure the cell
    
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
        var size:CGSize = CGSize.zero;
        if indexPath.section == 0 {
            size = CGSize(width:UIScreen.main.bounds.size.width,height:UIScreen.main.bounds.size.width * 1.0293)
        }
        else if indexPath.section == 1 {
            size = CGSize(width:UIScreen.main.bounds.size.width,height:UIScreen.main.bounds.size.height - UIScreen.main.bounds.size.width * 1.0293)
        }
        return size
    }
    func didClikDetail(){
        
    }
    
    func didClikOrder(){
    
    }
    func didClikContact(){
        UIApplication.shared.openURL(URL(string: "telprompt://10086")!)
    }

}
